﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VirtualPress.Infrastructure.Entities.Repository;
using VirtualPress.Infrastructure.Entities.Enum;

namespace VirtualPress.Infrastructure.Entities.Entity
{
    /// <summary>
    /// 账单表（待缴费记录表）
    /// </summary>
    public class Reckoning : IAccessible<T_Reckoning, Reckoning>, ILogicEntity<T_Reckoning, Reckoning>
    {
        #region Fileds
        public int Id { get; set; }

        /// <summary>
        /// 账单主人
        /// </summary>
        public string Own { get; set; }

        /// <summary>
        /// 支付类型
        /// 0：为稿件支付
        /// 1：期刊年费
        /// </summary>
        public int PayFor { get; set; }

        /// <summary>
        /// 关联ID
        /// payfor = 0  ： Manuscript.Id
        /// </summary>
        public int RaletionId { get; set; }

        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 支付时间
        /// </summary>
        public DateTime PayTime { get; set; }

        /// <summary>
        /// 支付额度
        /// </summary>
        public int TotalPay { get; set; }

        /// <summary>
        /// 支付类型
        /// 1：支付宝线上支付
        /// 9：线下支付
        /// </summary>
        public PayType PayType { get; set; }

        /// <summary>
        /// 账单状态
        /// 0：待支付
        /// 1：已支付待确认
        /// 2：支付完成
        /// 9：已关闭
        /// </summary>
        public BillStatus Status { get; set; }

        /// <summary>
        /// 支付交易号
        /// </summary>
        public string Txid { get; set; }

        public int PaymentStreamId { get; set; }

        public string Message { get; set; }
        #endregion

        public BillStream BillLog { get; set; }
        public Reckoning LoadBillLog(BillStream log)
        {
            this.BillLog = log;
            return this;
        }

        protected override void Covariant(T_Reckoning model)
        {
            if(model != null)
            {
                this.CreateTime = model.CreateTime;
                this.Id = model.Id;
                this.Message = model.Message;
                this.Own = model.Own;
                this.PayFor = model.PayFor;
                this.PaymentStreamId = model.PaymentStreamId;
                this.PayTime = model.PayTime;
                this.PayType = (PayType)model.PayType;
                this.RaletionId = model.RaletionId;
                this.Status = (BillStatus)model.Status;
                this.TotalPay = model.TotalPay;
                this.Txid = model.Txid;
            }
        }

        protected override T_Reckoning Inverter(Reckoning model)
        {
            return new T_Reckoning()
            {
                CreateTime = model.CreateTime,
                Id = model.Id,
                Message = model.Message,
                Own = model.Own,
                PayFor = model.PayFor,
                PaymentStreamId = model.PaymentStreamId,
                PayTime = model.PayTime,
                PayType = (int)model.PayType,
                RaletionId = model.RaletionId,
                Status = (int)model.Status,
                TotalPay = model.TotalPay,
                Txid = model.Txid
            };
        }

        public Reckoning Set(T_Reckoning dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}